Skip to content

PopupInfo

Base classes

Name Children Inherits
Dialog
prettyqt.widgets.dialog
The base class of dialog windows.

⋔ Inheritance diagram

graph TD
  2167664901["custom_widgets.PopupInfo"]
  4254570387["widgets.Dialog"]
  2345124717["widgets.DialogMixin"]
  829357528["widgets.WidgetMixin"]
  3227531497["core.ObjectMixin"]
  2751680898["builtins.object"]
  625385617["gui.PaintDeviceMixin"]
  392105360["QtWidgets.QDialog"]
  3620195106["QtWidgets.QWidget"]
  3984060476["QtCore.QObject"]
  37984305["Shiboken.Object"]
  673956333["QtGui.QPaintDevice"]
  4254570387 --> 2167664901
  2345124717 --> 4254570387
  829357528 --> 2345124717
  3227531497 --> 829357528
  2751680898 --> 3227531497
  625385617 --> 829357528
  2751680898 --> 625385617
  2751680898 --> 829357528
  2751680898 --> 2345124717
  392105360 --> 4254570387
  3620195106 --> 392105360
  3984060476 --> 3620195106
  37984305 --> 3984060476
  2751680898 --> 37984305
  673956333 --> 3620195106
  37984305 --> 673956333

🛈 DocStrings

Bases: Dialog

Dialog overlay to show some info to user.

Source code in prettyqt/custom_widgets/popupinfo.py
class PopupInfo(widgets.Dialog):
    """Dialog overlay to show some info to user."""

    _singleton: PopupInfo | None = None

    def __init__(self, parent: widgets.QWidget | None = None, text: str | None = None):
        super().__init__(parent=parent)
        self.timer = core.Timer(single_shot=True, timeout=self.close)
        self.label = widgets.Label(text or "", alignment="center")
        self.iconlabel = widgets.Label()
        self.set_icon("mdi.information")
        self.set_flags(stay_on_top=True, frameless=True, tooltip=True)
        layout = self.set_layout("horizontal", margin=20, size_constraint="minimum")
        self.set_background_color("black")
        self.label.set_color("white")
        layout.add(self.iconlabel)
        layout.add(self.label)
        self.hide()

    def set_text_color(self, color: datatypes.ColorType):
        self.label.set_color(color)

    def set_icon(self, icon: datatypes.IconType):
        pixmap = iconprovider.get_icon(icon, color="white").pixmap(32)
        self.iconlabel.setPixmap(pixmap)

    def show_popup(
        self,
        text: str,
        icon: datatypes.IconType = "mdi.information",
        text_color: datatypes.ColorType = "white",
        background_color: datatypes.ColorType = "black",
        position="screen",
        timeout: int = 2500,
    ):
        self.set_background_color(background_color)
        self.label.set_color(text_color)
        self.label.setText(text)
        self.set_icon(icon)
        self.adjustSize()
        self.position_on(position, y_offset=-200)
        self.timer.start(timeout)
        self.show()

    @classmethod
    def popup(
        cls,
        text: str,
        icon: datatypes.IconType = "mdi.information",
        text_color: datatypes.ColorType = "white",
        background_color: datatypes.ColorType = "black",
        position="screen",
        timeout: int = 2500,
    ):
        if cls._singleton is None:
            cls._singleton = cls()
        popup = cls._singleton
        popup.set_background_color(background_color)
        popup.label.set_color(text_color)
        popup.label.setText(text)
        popup.set_icon(icon)
        popup.adjustSize()
        popup.position_on(position, y_offset=-200)
        popup.timer.start(timeout)
        popup.show()

:fa-brands-github: Show source on GitHub